Ordered hashing: insertion


procedure insert( key : typekey; var r : dataarray ); var i : integer; temp : typekey; begin if n>=m then Error {*** table is full ***} else begin i := hashfunction( key ) ; while (not empty(r[i])) and (not deleted(r[i])) and (r[i].k<>key) do begin if r[i].k > key then begin {*** Exchange key and continue ***} temp := key; key := r[i].k; r[i].k := temp end; i := (i+increment(key)) mod m end; if empty(r[i]) or deleted(r[i]) then begin {*** do insertion ***} r[i].k := key; n := n+1 end else Error {*** key already in table ***} end end;

Pascal source (337.ins.p)



© Addison-Wesley Publishing Co. Inc.